package cn.it62.pojo;
import java.util.Scanner;
/**
 * @author zhenhuaShen
 * @version 1.0
 * @date 2019/7/25
 * @description cn.it62.pojo
 */
public class Computer {
    Scanner sc = new Scanner(System.in);
    public String operator;
    public double firstNumber;
    public double secondNumber;

    public void Calculation() {
        double sum=0;
        while (true) {
            System.out.print("请输入计算符号:");
            operator = sc.next();
            if (operator.equals("+") || operator.equals("-") || operator.equals("*") || operator.equals("/")) {
                break;
            } else {
                System.out.println("输入错误,请重新输入");
            }
        }
        while (true) {
            System.out.print("请输入第一个数：");
            if (sc.hasNextDouble()) {
                firstNumber = sc.nextInt();
                if (firstNumber <= 0) {
                    System.out.println("firstNumber只能是正整数");
                    continue;
                }
                break;
            } else {
                System.out.println("firstNumber只能是正整数，输入的是：" + sc.next());
            }
        }
        while (true) {
            System.out.print("请输入第二个数：");
            if (sc.hasNextDouble()) {
                secondNumber = sc.nextInt();
                if (secondNumber <= 0) {
                    System.out.println("secondNumber只能是正整数");
                    continue;
                }
                break;
            } else {
                System.out.println("secondNumber只能是正整数，输入的是：" + sc.next());
            }
        }
        switch (operator) {
            case "+": {

                sum = firstNumber + secondNumber;
                break;
            }
            case "-": {
                sum = firstNumber - secondNumber;
                break;
            }
            case "*": {
                sum = firstNumber - secondNumber;
                break;
            }
            case "/": {
                sum = firstNumber / secondNumber;
                break;
            }

        }
        System.out.println(firstNumber + operator + secondNumber + "=" + sum);
    }
}
